package com.bhs.sansonglogistics.ui.adapter;

import android.text.TextUtils;
import android.view.View;
import android.widget.Button;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bhs.sansonglogistics.R;
import com.bhs.sansonglogistics.bean.Location;
import com.bhs.sansonglogistics.bean.OrderGoodsBean;
import com.bhs.sansonglogistics.utils.DateUtils;
import com.bhs.sansonglogistics.utils.GetDistanceUtils;
import com.bhs.sansonglogistics.utils.MyUtils;
import com.bhs.sansonglogistics.utils.SharedPreferencesUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

public class SourceGoodsAdapter extends BaseQuickAdapter<OrderGoodsBean, BaseViewHolder> {

    private int type;//1指派 2极速


    public SourceGoodsAdapter(int layoutResId, int type) {
        super(layoutResId);
        this.type = type;

    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, OrderGoodsBean item) {
        Button btnImmediateOffer = helper.getView(R.id.btn_immediate_offer);
        if (item.getDeliver_type() == 3) {
            btnImmediateOffer.setVisibility(View.VISIBLE);
            if (!TextUtils.isEmpty(item.getQuoted_price()) && !item.getQuoted_price().equals("0")) {
                btnImmediateOffer.setText("查看报价");
            } else {
                btnImmediateOffer.setText("报价");
            }
        } else {
            btnImmediateOffer.setVisibility(View.GONE);
        }

        helper.setVisible(R.id.btn_refuse, type == 1);
        helper.setText(R.id.btn_preempt, type == 2 ? "抢单" : "接单");
        helper.addOnClickListener(R.id.btn_immediate_offer).addOnClickListener(R.id.btn_preempt).addOnClickListener(R.id.btn_refuse);
        helper.setText(R.id.tv_type, item.getIs_yuyue() == 0 ? "即时" : DateUtils.descriptiveData(item.getYuyue_time()));
        helper.setBackgroundRes(R.id.ll_top, item.getIs_yuyue() == 0 ? R.drawable.bg_top_red_fillet : R.drawable.bg_top_blue_fillet);
        if (!TextUtils.isEmpty((item.getPickup_longitude())) && Location.companyLon > 0) {
            helper.setVisible(R.id.tv_distance, true);
            helper.setText(R.id.tv_distance, String.format("距您%s公里", GetDistanceUtils.getDistance(Double.parseDouble(item.getPickup_longitude())
                    , Double.parseDouble(item.getPickup_latitude()), Location.companyLon, Location.companyLat)));
        } else {
            helper.setVisible(R.id.tv_distance, false);
        }
        helper.setText(R.id.tv_place_departure, item.getPickup_city());
        helper.setText(R.id.tv_destination, item.getReceive_city());
        helper.setText(R.id.tv_departure_address, item.getPickup_address());
        helper.setText(R.id.tv_delivery_type, MyUtils.getDeliveryType(item.getJiaohuo_type()));
        helper.setText(R.id.tv_arrival_address, item.getReceive_address());
        helper.setText(R.id.tv_distribution_type, MyUtils.getDistributionType(item.getPeisong_type()));
        helper.setText(R.id.tv_haulage_time, MyUtils.getHaulageTime(item.getDeliver_type(), item.getTransport_day_max(), item.getTransport_day_min()));
        helper.setText(R.id.tv_cargo_time, String.format("%s/%s件/%s吨/%s立方", item.getGoods_name(), item.getGoods_number(),
                MyUtils.checkPoint(item.getGoods_weight()), MyUtils.checkPoint(item.getGoods_volume())));
        helper.setText(R.id.tv_added_services, String.format("%s%s", MyUtils.getReceiptType(item.getReceipt_type()), MyUtils.isInvoice(item.getIs_invoice())));
        helper.setText(R.id.tv_order_time, String.format("下单时间：%s", DateUtils.descriptiveData(item.getCreate_time())));
        helper.setText(R.id.tv_order_price, String.format("￥%s", MyUtils.getPayStatus(item.getLast_price(), item.getLast_price(), item.getPay_status(), item.getPay_method())));
        //quoted_price 报价按钮状态 >0不等于空
    }
}
